]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
workspacesView: Center active workspace in allocation
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Wed, 30 Dec 2020 15:44:00 +0000 (12:44 -0300)
committerMarge Bot <marge-bot@gnome.org>
Wed, 3 Feb 2021 20:30:30 +0000 (20:30 +0000)
When vertically snapping, WorkspacesView currently allocates workspaces
side-by-side, then applies an extra step of translation to center to
the active workspace. This extra step, however, gets in our way because
now we need tighter control of the workspaces positions in allocation,
in order to properly interpolate them.

Move the translation of workspaces to the allocation code itself, and
remove the extra translation step.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1613>

js/ui/workspacesView.js

index 93782f431b2af6f4c171ccc726b27d30ddc75c12..36a15a71ff5ca47b19b8ea2b13d476f4bb878332 100644 (file)
@@ -162,15 +162,22 @@ class WorkspacesView extends WorkspacesViewBase {
         const [width, height] = box.get_size();
         const [workspace] = this._workspaces;
 
+        const rtl = this.text_direction === Clutter.TextDirection.RTL;
+        const adj = this._scrollAdjustment;
+        const currentWorkspace = vertical || !rtl
+            ? adj.value : adj.upper - adj.value;
+
         // Single fit mode implies centered too
         let x1 = 0;
         let y1 = 0;
         if (vertical) {
             const [, workspaceHeight] = workspace.get_preferred_height(width);
             y1 += (height - workspaceHeight) / 2;
+            y1 -= currentWorkspace * (workspaceHeight + spacing);
         } else {
             const [, workspaceWidth] = workspace.get_preferred_width(height);
             x1 += (width - workspaceWidth) / 2;
+            x1 -= currentWorkspace * (workspaceWidth + spacing);
         }
 
         const fitSingleBox = new Clutter.ActorBox({ x1, y1 });
@@ -257,8 +264,6 @@ class WorkspacesView extends WorkspacesViewBase {
                     fitAllBox.y1);
             }
         });
-
-        this._updateScrollPosition();
     }
 
     getActiveWorkspace() {
@@ -270,7 +275,6 @@ class WorkspacesView extends WorkspacesViewBase {
     animateToOverview() {
         for (let w = 0; w < this._workspaces.length; w++)
             this._workspaces[w].zoomToOverview();
-        this._updateScrollPosition();
         this._updateVisibility();
     }
 
@@ -306,10 +310,13 @@ class WorkspacesView extends WorkspacesViewBase {
         let workspaceManager = global.workspace_manager;
         let active = workspaceManager.get_active_workspace_index();
 
+        const fitMode = this._fitModeAdjustment.value;
+        const singleFitMode = fitMode === FitMode.SINGLE;
+
         for (let w = 0; w < this._workspaces.length; w++) {
             let workspace = this._workspaces[w];
 
-            if (this._animating || this._gestureActive)
+            if (this._animating || this._gestureActive || !singleFitMode)
                 workspace.show();
             else
                 workspace.visible = Math.abs(w - active) <= 1;
@@ -342,8 +349,6 @@ class WorkspacesView extends WorkspacesViewBase {
             this._workspaces[j].destroy();
             this._workspaces.splice(j, 1);
         }
-
-        this._updateScrollPosition();
     }
 
     _activeWorkspaceChanged(_wm, _from, _to, _direction) {
@@ -406,44 +411,7 @@ class WorkspacesView extends WorkspacesViewBase {
             metaWorkspace.activate(global.get_current_time());
         }
 
-        this._updateScrollPosition();
-    }
-
-    _updateScrollPosition() {
-        if (!this.has_allocation())
-            return;
-
-        const adj = this._scrollAdjustment;
-
-        if (adj.upper == 1)
-            return;
-
-        const workspaceManager = global.workspace_manager;
-        const vertical = workspaceManager.layout_rows === -1;
-        const rtl = this.text_direction === Clutter.TextDirection.RTL;
-        const fitMode = this._fitModeAdjustment.value;
-        let progress = vertical || !rtl
-            ? adj.value : adj.upper - adj.value - 1;
-        progress = Util.lerp(progress / (adj.upper - 1), 0, fitMode);
-
-        // Use workspaces geometry to determine the size to offset
-        const firstWorkspaceBox = rtl
-            ? this._workspaces[this._workspaces.length - 1].allocation
-            : this._workspaces[0].allocation;
-        const lastWorkspaceBox = rtl
-            ? this._workspaces[0].allocation
-            : this._workspaces[this._workspaces.length - 1].allocation;
-        const [workspaceWidth, workspaceHeight] = firstWorkspaceBox.get_size();
-        const size = vertical
-            ? lastWorkspaceBox.y2 - firstWorkspaceBox.y1 - workspaceHeight
-            : lastWorkspaceBox.x2 - firstWorkspaceBox.x1 - workspaceWidth;
-
-        for (const ws of this._workspaces) {
-            if (vertical)
-                ws.translation_y = -progress * size;
-            else
-                ws.translation_x = -progress * size;
-        }
+        this.queue_relayout();
     }
 });